import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
import HomePage from '@/views/HomePage/index.vue'
import singer from '@/views/Singer/index.vue'
import songList from '@/views/SongList/index.vue'
import myMusic from '@/views/Mymusic/index.vue'
import fondMusic from '@/views/FondMusic/index.vue'
import SearchPage from '@/components/searchPage.vue'


 
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/fondMusic'
    },
    {
      path: '/homepage',
      component: HomePage,
      children:[
        {
          path:'/fondMusic',
          component:fondMusic
        },
        {
          path:'/songList',
          component:songList
        },
        {
          path:'/singer',
          component:singer
        },
        {
          path:'/myMusic',
          component:myMusic
        },
        {
          path:'/search',
          component:SearchPage
        }
      ]
    }
  ]
})



router.beforeEach((to, from, next) => {

  if (to.path === '') {
    next('/'); 
  } else {
    next();
  }
});

export default router
